package com.example.pceb.result;

import lombok.Data;

import java.util.Date;



import java.util.Date;

@Data
public class Result<T> {

    private int code;
    private String message;
    private T data;
    private final Date time = new Date();


    public Result() {}


    public Result(T data, int code) {
        this.data = data;
        this.code = code;
        this.message = "success";
    }


    public Result(T data, String message) {
        this.data = data;
        this.message = message;
        this.code = ResultCode.OK.getCode(); // 设置默认成功码
    }



    public Result(String message,int code) {

        this.message = message;
        this.code = code;
    }


    // 新增构造方法支持ResultCode
    public Result(T data, int code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    // 保持原有方法
    public static <T> Result<T> success(T data) {
        return new Result<>(data, ResultCode.OK.getCode());
    }

    public static <T> Result<T> success(T data, ResultCode successCode) {
        return new Result<>(data, successCode.getCode(), successCode.getDescription());
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<>(data, message);
    }

    // 新增方法
    public static <T> Result<T> success() {
        return new Result<>(null, ResultCode.OK.getCode(), "操作成功");
    }

    public static <T> Result<T> fail(String message, ResultCode resultCode) {
        return new Result<>(message, resultCode.getCode());
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(message, ResultCode.FAIL.getCode());
    }

    public static <T> Result<T> notFound(String message) {
        return new Result<>(message, ResultCode.NOT_FOUND.getCode());
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(message, ResultCode.ERROR.getCode());
    }
}